<?php

namespace App\Models;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Goods
 * @package App\Models
 * @version February 18, 2018, 3:18 pm UTC
 *
 * @property string title
 * @property string abstract
 * @property string pic
 * @property float length
 * @property float wide
 * @property integer category_id
 * @property decimal price
 * @property float gram_weight
 * @property string describe
 * @property integer read_num
 * @property integer like_num
 * @property integer on_sell
 * @property integer sort
 */
class Goods extends Model
{
    use SoftDeletes;

    public $table = 'goods';
    

    protected $dates = ['deleted_at'];


    public $fillable = [
        'sn',
        'title',
        'abstract',
        'pic',
        'length',
        'wide',
        'category_id',
        'price',
        'gram_weight',
        'texture',
        'technology',
        'describe',
        'read_num',
        'like_num',
        'on_sell',
        'show_price',
        'sort'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'title' => 'string',
        'abstract' => 'string',
        'pic' => 'string',
        'length' => 'float',
        'wide' => 'float',
        'category_id' => 'integer',
        'gram_weight' => 'float',
        'describe' => 'string',
        'read_num' => 'integer',
        'like_num' => 'integer',
        'on_sell' => 'integer',
        'sort' => 'integer'
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        
    ];

    public function slideshows()
    {
        return $this->hasMany('App\Models\GoodsSlideshow');
    }

    public function articles()
    {
        return $this->belongsToMany('App\Models\Article','goods_article');
    }

    public function products()
    {
        return $this->belongsToMany('App\Models\Goods','goods_product','goods_id','product_id');
    }

    public function colors()
    {
        return $this->belongsToMany('App\Models\Color','goods_color');
    }

    public function labels()
    {
        return $this->belongsToMany('App\Models\Label','goods_label');
    }

    public function category()
    {
        return $this->belongsTo('App\Models\Category');
    }
}
